package com.starchen.optimalselection.product.controller;

import com.starchen.optimalselection.common.model.ResultPage;
import com.starchen.optimalselection.common.utils.Result;
import com.starchen.optimalselection.common.model.vo.SpuSaveVo;
import com.starchen.optimalselection.common.model.vo.SpuQueryVo;
import com.starchen.optimalselection.common.service.SpuInfoService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * spu信息
 *
 * @author daxilong
 * @email daxilong@gmail.com
 * @date 2022-08-14 19:57:36
 */
@Api(tags = "SPU管理")
@RestController
@RequestMapping("product/spuinfo")
public class SpuInfoController {

    @Autowired
    private SpuInfoService spuInfoService;

    @RequestMapping("/create")
    public Result save(@RequestBody SpuSaveVo vo){
        spuInfoService.saveSpuInfo(vo);
        return Result.success();
    }

    @RequestMapping("/page")
    public Result list(SpuQueryVo params){
        ResultPage page = spuInfoService.queryPage(params);

        return Result.success(page);
    }

    /**
     * 上架
     */
    @RequestMapping("/productup/{id}")
    public Result up(@PathVariable("id") Long spuId){
        spuInfoService.statusUp(spuId);
        return Result.success();
    }

}
